/*
 * Copyright 2012 Finbudget.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package finbudgettable.client.ui.grid.cell.string;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import finbudgettable.client.ui.grid.cell.input.InputEditableCell;

public class StringCell extends InputEditableCell<String> {

    interface Resources extends ClientBundle {

        interface Style extends CssResource {

            @ClassName("b-string-cell__text")
            String bStringCell__text();

            @ClassName("b-string-cell__multiline_text")
            String bStringCell__multiline_text();

            @ClassName("b-string-cell__input")
            String bStringCell__input();

            @ClassName("b-string-cell")
            String bStringCell();

            @ClassName("b-string-filter-panel")
            String bStringFilterPanel();
        }

        @Source("StringCell.css")
        Style style();
    }

    static final Resources RESOURCES = GWT.create(Resources.class);

    static {
        RESOURCES.style().ensureInjected();
    }


    public StringCell(boolean nullable) {
        super(nullable);
    }

    @Override
    protected boolean validate(String value) {
        return true;
    }

    @Override
    protected String convertValueToEditedValue(String value) {
        return value != null ? value : "";
    }

    @Override
    protected String convertEditedValueToValue(String editedValue) {
        return editedValue;
    }

    @Override
    protected String getValueToDisplay(String value) {
        return value != null ? value : "";
    }

    @Override
    protected String getInnerCellClassName() {
        if (isMultilineStyle()) {
            return RESOURCES.style().bStringCell__multiline_text();
        } else {
            return RESOURCES.style().bStringCell__text();
        }
    }
}